/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.ycl.ybk.e2p.yb.tools;

import cn.ac.iie.di.ban.ycl.ybk.e2p.yb.main.BanBkE2p;
import static cn.ac.iie.di.ban.ycl.ybk.e2p.yb.main.BanBkE2p.mediaclient;
import cn.ac.iie.di.ban.ycl.ybk.e2p.yb.service.FJRThreadTask;
import cn.ac.iie.di.ban.ycl.ybk.e2p.yb.tools.fastutil.FastPo;
import cn.ac.iie.di.ban.ycl.ybk.e2p.yb.tools.fastutil.FileManagerUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.http.HttpEntity;
//import org.apache.commons.httpclient.HttpClient;
//import org.apache.commons.httpclient.HttpStatus;
//import org.apache.commons.httpclient.methods.PostMethod;
//import org.apache.commons.httpclient.methods.multipart.FilePart;
//import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
//import org.apache.commons.httpclient.methods.multipart.Part;
//import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.log4j.Logger;
import org.apache.commons.io.FileUtils;

/**
 *
 * @author wmr
 */
public class JsonUtil {
    
    private static Logger logger = Logger.getLogger(JsonUtil.class);
    //元信息初始化一次
//    private static String[] urls = null;
//    private static String[] urlsN = null;
    private static String sendTimeout = null;
//    private static String orclFilePath = BanBkE2p.confDir + "/server.properties";
    private static String orclFilePath = ClassLoader.getSystemClassLoader().getResource("server.properties").getFile();
//    private static String orclFilePath = "/home/wmr/NetBeansProjects/Maven_project/ban-bk-e2p-ysyb_new/src/main/resources" + "/oracle_jdbc.properties";

    private static String sampleUrlStr = "";
    private static String sampleUrlStrNo = "";
    private static String userUrlStr = "";
    private static String userUrlStrNo = "";
    private static String orderUrlStr = "";
    private static String orderUrlStrNo = "";
    
    static {
        try {
            Properties prop = new Properties();
            InputStream in = new FileInputStream(orclFilePath);
            prop.load(in);
            in.close();
            sendTimeout = prop.getProperty("sendTimeout").trim();
            
            sampleUrlStr = prop.getProperty("sampleUrls").trim();
            sampleUrlStrNo = prop.getProperty("sampleUrlsNo").trim();
            
            userUrlStr = prop.getProperty("userUrls").trim();
            userUrlStrNo = prop.getProperty("userUrlsNo").trim();
            
            orderUrlStr = prop.getProperty("orderUrls").trim();
            orderUrlStrNo = prop.getProperty("orderUrlsNo").trim();
//            urls = urlStr.split(";");
//            urlsN = urlStrNo.split(";");
        } catch (Exception e) {
            logger.error(" Failed to get the url " + e.getMessage(), e);
        }
    }
    
    public static boolean jsonData(String localFilePath, HashMap<String, FastPo> fDfsRetStrMap, List<Map<String, String>> dataFileList, String src) {
        boolean flag = true;
        String[] urls = null;//请求霍亚宁接口url
        String[] urlsN = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String currenttime = sdf.format(new Date());
        
        try {
            //
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            logger.info(" JsonUtil start " + df.format(new Date()));
            //sql
            //文件是否可用
//            boolean flag = true;
            //获取需要处理的文件列表

            List<String> jsonFileList = new ArrayList<String>();
            Map<String, String> fileMap = new HashMap<String, String>();
            for (int i = 0; i < dataFileList.size(); i++) {
                Map<String, String> str = dataFileList.get(i);
                String lastFilename = str.get("name");
                String realName = lastFilename.substring(lastFilename.lastIndexOf("/") + 1, lastFilename.length());
                String dataFileName = localFilePath + lastFilename;
                String okFileName = localFilePath + lastFilename + ".ok";
                File dataf = new File(dataFileName);
                File okf = new File(okFileName);
//            if (okf.exists() && dataf.exists()) {
                if (dataf.exists()) {
                    if (realName.endsWith(".json")) {
                        jsonFileList.add(lastFilename);
                    } else {
                        String md5N = realName.substring(0, realName.lastIndexOf("."));
                        fileMap.put(md5N, lastFilename);
                        
                    }
                }
            }
            
            if (jsonFileList.size() == 0) {
                FJRThreadTask.errorFlag = 1;
                flag = false;
                logger.error(" JSON file does not exist");
                return flag;
            }
            //处理每个文件
            //没有数据文件
            if (fDfsRetStrMap.size() == 0 || fDfsRetStrMap.isEmpty()) {
                for (int k = 0; k < jsonFileList.size(); k++) {
                    String JsonContext = null;
                    JSONObject ob = null;
                    String jsonFilePath = null;
                    if (flag) {
                        
                        jsonFilePath = localFilePath + jsonFileList.get(k);
//                    jsonFilePath = "/home/wmr/NetBeansProjects/datatest/LoadSample.json";
                        logger.info(" Get JSON file path: " + jsonFilePath + "   " + df.format(new Date()));
                        //读取json文件内容
                        JsonUtil jsonUtil = new JsonUtil();
//                    String JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        if (JsonContext == null) {
                            
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("failed to get JSON string");
                            return flag;
                        }
                        logger.debug(" JsonContext -------- " + JsonContext);
                        
                        try {
                            ob = JSONObject.parseObject(JsonContext);
                        } catch (Exception e) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error(" JSON file error" + e.getMessage(), e);
                            return flag;
                        }

                        //获得并处理每条记录
                        //解析dataType接口类型
                        String returndata = ob.get("dataType").toString();
                        if (returndata == null || returndata.isEmpty()) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("get dataType failed **************");
                            return flag;
                        } else if (returndata.equals("userInfo")) {
                            urls = userUrlStr.split(";");
                            urlsN = userUrlStrNo.split(";");
                        } else if (returndata.equals("sampleInfo")) {
                            urls = sampleUrlStr.split(";");
                            urlsN = sampleUrlStrNo.split(";");
                        } else if (returndata.equals("orderInfo")) {
                            urls = orderUrlStr.split(";");
                            urlsN = orderUrlStrNo.split(";");
                        }
                    }// end if (flag ) ** if bad data
                    while (true) {
                        int stat = 0;
                        for (int i = 0; i < urlsN.length; i++) {
//                            stat = JsonUtil.httpPost(urlsN[i], JsonContext, true);
                            stat = JsonUtil.httpPost(urlsN[i], new File(jsonFilePath));
                            if (stat == 200) {
//                                logger.info("json send ok !!!");
                                logger.info("json send urlN " + urlsN[i] + " send ok !!!");
                                break;
                            } else {
//                                失败的话重试20次啊20次
//                                int count = 0;
//                                while (count < 20) {
//                                    int random = (int) (Math.random() * urlsN.length);
//                                    logger.info("json send urlN random:" + random + ",url = " + urls[random]);
//                                    stat = JsonUtil.httpPost(urlsN[random], new File(jsonFilePath));
//                                    if (stat == 200) {
//                                        logger.info("json send url " + urlsN[random] + " send ok !!!");
//                                        break;
//                                    }
//                                    count++;
//                                }
                            }
                        }
                        Thread.sleep(5000);
                        if (stat == 200) {
                            logger.info("json send ok !!!");
                            break;
                        }
                    }
                }//end handle json file
            } else {//有数据文件
                for (int k = 0; k < jsonFileList.size(); k++) {
                    String JsonContext = null;
                    JSONObject ob = null;
                    String jsonFilePath = null;
                    if (flag) {
                        
                        jsonFilePath = localFilePath + jsonFileList.get(k);
//                    jsonFilePath = "/home/wmr/NetBeansProjects/datatest/LoadSample.json";
                        logger.info(" Get JSON file path: " + jsonFilePath + "   " + df.format(new Date()));
                        //读取json文件内容
                        JsonUtil jsonUtil = new JsonUtil();
//                    String JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        if (JsonContext == null) {
                            
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("failed to get JSON string");
                            return flag;
                        }
                        try {
                            ob = JSONObject.parseObject(JsonContext);
//                            ob = new JSONObject(JsonContext);
                        } catch (Exception e) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error(" JSON file error" + e.getMessage(), e);
                            return flag;
                        }

                        //获得并处理每条记录
                        String returndata = ob.get("dataType").toString();
                        if (returndata == null || returndata.isEmpty()) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("get dataType failed **************");
                            return flag;
                        } else if (returndata.equals("userInfo")) {
                            urls = userUrlStr.split(";");
                            urlsN = userUrlStrNo.split(";");
                            
                            JSONArray dataArray = ob.getJSONArray("record_list");
                            
                            if (dataArray.size() == 0) {
                                FJRThreadTask.errorFlag = 2;
                                flag = false;
                                logger.error(" data file count is 0 **************");
                                return flag;
                            }

//                    if (fDfsRetStrMap.size() == dataArray.size()) {
                            //把上传至FastDfs返回的map值插入到data下的json文件fileurl，fileicon中
//                        String lcPath = "/ybkdata/yb/";
                            for (int i = 0; i < dataArray.size(); i++) {
                                String lcPath = BanBkE2p.lcPathBase;
                                JSONObject jsonObject = dataArray.getJSONObject(i);
                                jsonObject.put("sourceSystemCode", src);
                                String dataType = jsonObject.get("typeName").toString();
                                
                                if (dataType == null || dataType.equals("")) {
                                    logger.info("typeName ------  does not exist");
                                    continue;
                                }
                                Date dt = new Date();
                                SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
                                String dataTime = matter1.format(dt);
                                String fmd5 = jsonObject.get("fileMd5").toString();
                                if (fmd5 == null || fmd5.equals("")) {
                                    logger.info("fileMd5 ------  does not exist");
                                    continue;
                                }
                                logger.info("json fileMd5 ------------: " + fmd5);
                                lcPath = lcPath + dataType + "/" + dataTime + "/" + fmd5 + "/";
                                Map<String, String> lcDfMap = new HashMap<String, String>();
                                boolean attachFlag = true;
                                JSONArray attachArray = null;
                                try {
                                    attachArray = jsonObject.getJSONArray("attachmentList");
                                    if (attachArray.isEmpty() || attachArray.size() == 0 || attachArray == null) {
                                        logger.info("attachmentList no object !!!");
                                        attachFlag = false;
//                                    continue;
                                    } else {
                                        attachFlag = true;
                                    }
                                } catch (Exception e) {
                                    logger.info("attachmentList no exist!!!" + e.getMessage(), e);
                                    attachFlag = false;
//                                continue;
                                }
                                
                                if (attachFlag) {
                                    for (int t = 0; t < attachArray.size(); t++) {
                                        JSONObject attachObject = attachArray.getJSONObject(t);
                                        String arrMd5 = attachObject.get("fileMd5").toString();
                                        if (arrMd5 == null || arrMd5.equals("")) {
                                            logger.info("arrMd5 ------  does not exist");
                                            continue;
                                        }
                                        FastPo attachfastPo = fDfsRetStrMap.get(attachObject.get("fileMd5").toString());
//                                    String lcSecPath = lcDfMap.get(attachObject.get("md5").toString());
                                        String ctrlDataPath = fileMap.get(attachObject.get("fileMd5").toString());
                                        String lcHalfPath = attachObject.get("relativePath").toString();
                                        if (lcHalfPath == null || lcHalfPath.equals("") || lcHalfPath.equals(" ")) {
                                            lcHalfPath = attachObject.get("originFileName").toString();
                                        } else {
                                            lcHalfPath = lcHalfPath.substring(lcHalfPath.indexOf("/") + 1, lcHalfPath.length());
                                        }
                                        String oldDataPath = localFilePath + ctrlDataPath;
                                        String newDataPath = lcPath + lcHalfPath;
                                        JsonUtil.copyFile(oldDataPath, newDataPath);
                                        String attachfpath = attachfastPo.getFilePath();
                                        logger.info("attachfpath - " + attachfpath);
                                        attachObject.put("attachmentUrl", newDataPath);
                                        attachObject.put("mmsAttachmentUrl", attachfastPo.getFilePath());
                                        lcDfMap.put(attachObject.get("fileMd5").toString(), newDataPath);
                                    }
                                }
                                //处理主表字段
                                FastPo fastPo = fDfsRetStrMap.get(jsonObject.get("fileMd5").toString());
                                if (fastPo == null) {
                                    logger.info("no datafile match json -----------------------!!");
                                    continue;
                                }
                                String lcMainFilePath = lcDfMap.get(fmd5);
                                if (lcMainFilePath == null) {
                                    logger.info("no datafile match lcPath -----------------------!!");
                                    String ctrlDataPath = fileMap.get(fmd5);
                                    String oldDataPath = localFilePath + ctrlDataPath;
                                    String lcN = ctrlDataPath.substring(ctrlDataPath.lastIndexOf("/") + 1, ctrlDataPath.length());
                                    String newDataPath = lcPath + lcN;
                                    JsonUtil.copyFile(oldDataPath, newDataPath);
                                    lcMainFilePath = newDataPath;
//                                continue;
                                }
                                logger.info("fileUrl fileShowUrl fileUrlmms fileShowUrlmms put json !!");
                                jsonObject.put("fileUrl", lcMainFilePath);
                                jsonObject.put("fileShowUrl", lcMainFilePath);
                                //mmsFileUrl mmsFileShowUrl
//                                jsonObject.put("fileUrlmms", fastPo.getFilePath());
//                                jsonObject.put("fileShowUrlmms", fastPo.getFilePath());
                                jsonObject.put("mmsFileUrl", fastPo.getFilePath());
                                jsonObject.put("mmsFileShowUrl", fastPo.getFilePath());
                                
                                logger.info("fileUrl fileShowUrl fileUrlmms fileShowUrlmms put json end !!");
//                            JSONArray attachArray = jsonObject.getJSONArray("attachmentList");
//                            try {
//                                JSONArray attachArray = jsonObject.getJSONArray("attachmentList");
//                                if (attachArray.isEmpty() || attachArray.size() == 0) {
//                                    logger.info("attachmentList no object !!!");
//                                    continue;
//                                }
//                                for (int t = 0; t < attachArray.size(); t++) {
//                                    JSONObject attachObject = attachArray.getJSONObject(t);
//                                    FastPo attachfastPo = fDfsRetStrMap.get(attachObject.get("md5").toString());
//                                    String lcSecPath = lcDfMap.get(attachObject.get("md5").toString());
//                                    String attachfpath = attachfastPo.getFilePath();
//                                    logger.info("attachfpath - " + attachfpath);
//                                    attachObject.put("location", lcSecPath);
//                                    attachObject.put("mmslocation ", attachfastPo.getFilePath());
//                                }
//                            } catch (Exception e) {
//                                logger.info("attachmentList no exist!!!" + e.getMessage(), e);
//                                continue;
//                            }

                            }//end handle record   

                        } else if (returndata.equals("sampleInfo")) {
                            urls = sampleUrlStr.split(";");
                            urlsN = sampleUrlStrNo.split(";");
                            
                            JSONArray dataArray = ob.getJSONArray("record_list");
                            
                            if (dataArray.size() == 0) {
                                FJRThreadTask.errorFlag = 2;
                                flag = false;
                                logger.error(" data file count is 0 **************");
                                return flag;
                            }

//                    if (fDfsRetStrMap.size() == dataArray.size()) {
                            //把上传至FastDfs返回的map值插入到data下的json文件fileurl，fileicon中
//                        String lcPath = "/ybkdata/yb/";
                            for (int i = 0; i < dataArray.size(); i++) {
                                String lcPath = BanBkE2p.lcPathBase;
                                JSONObject jsonObject = dataArray.getJSONObject(i);
                                String dataType = jsonObject.get("typeName").toString();
                                if (dataType == null || dataType.equals("")) {
                                    logger.info("typeName ------  does not exist");
                                    continue;
                                }
                                Date dt = new Date();
                                SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
                                String dataTime = matter1.format(dt);
                                String fmd5 = jsonObject.get("fileMd5").toString();
                                if (fmd5 == null || fmd5.equals("")) {
                                    logger.info("fileMd5 ------  does not exist");
                                    continue;
                                }
                                
                                String containFile = "true";
                                try {
                                    containFile = jsonObject.get("containFile").toString();
                                } catch (Exception e) {
                                    logger.info("json fileMd5 is " + fmd5 + " doesn't have contailFile!!!" + e.getMessage(), e);
                                }
                                
                                logger.info("json fileMd5 ------------: " + fmd5 + " ,and the containFile is " + containFile);
                                lcPath = lcPath + dataType + "/" + dataTime + "/" + fmd5 + "/";
                                Map<String, String> lcDfMap = new HashMap<String, String>();
                                boolean attachFlag = true;
                                JSONArray attachArray = null;
                                try {
                                    attachArray = jsonObject.getJSONArray("attachmentList");
                                    if (attachArray.isEmpty() || attachArray.size() == 0 || attachArray == null) {
                                        logger.info("attachmentList no object !!!");
                                        attachFlag = false;
//                                    continue;
                                    } else {
                                        attachFlag = true;
                                    }
                                } catch (Exception e) {
                                    logger.info("attachmentList no exist!!!" + e.getMessage(), e);
                                    attachFlag = false;
//                                continue;
                                }
                                
                                if (attachFlag) {
                                    for (int t = 0; t < attachArray.size(); t++) {
                                        JSONObject attachObject = attachArray.getJSONObject(t);
                                        String arrMd5 = attachObject.get("fileMd5").toString();
                                        if (arrMd5 == null || arrMd5.equals("")) {
                                            logger.info("arrMd5 ------  does not exist");
                                            continue;
                                        }
                                        FastPo attachfastPo = fDfsRetStrMap.get(attachObject.get("fileMd5").toString());
//                                    String lcSecPath = lcDfMap.get(attachObject.get("md5").toString());
                                        String ctrlDataPath = fileMap.get(attachObject.get("fileMd5").toString());
                                        String lcHalfPath = attachObject.get("relativePath").toString();
                                        if (lcHalfPath == null || lcHalfPath.equals("") || lcHalfPath.equals(" ")) {
                                            lcHalfPath = attachObject.get("originFileName").toString();
                                        } else {
                                            lcHalfPath = lcHalfPath.substring(lcHalfPath.indexOf("/") + 1, lcHalfPath.length());
                                        }
                                        String oldDataPath = localFilePath + ctrlDataPath;
                                        String newDataPath = lcPath + lcHalfPath;
                                        logger.info(arrMd5 + " begin to copy lc!!!");
                                        JsonUtil.copyFile(oldDataPath, newDataPath);
                                        //双写多媒体库,并添加字段
//                                        String returnKey = uploadFile2Multimedia(oldDataPath);
                                        //mmsAttachmentUrl
                                        attachObject.put("mmsAttachmentUrl", attachfastPo.getFilePath());
                                        attachObject.put("attachmentUrl", newDataPath);
                                        String attachfpath = attachfastPo.getFilePath();
//                                        logger.info("attachfpath - " + attachfpath);
//                                        attachObject.put("location", newDataPath);
//                                        attachObject.put("mmslocation", attachfastPo.getFilePath());
                                        lcDfMap.put(attachObject.get("fileMd5").toString(), newDataPath);
                                    }
                                }
                                //处理主表字段
                                FastPo fastPo = fDfsRetStrMap.get(jsonObject.get("fileMd5").toString());
                                if (fastPo == null) {
                                    logger.info("no datafile match json -----------------------!!");
                                    continue;
                                }
                                if (containFile != "false") {
                                    String lcMainFilePath = lcDfMap.get(fmd5);
//                                    String uploadFile2Multimedia = "";
                                    if (lcMainFilePath == null) {
                                        logger.info("no datafile match lcPath -----------------------!!");
                                        String ctrlDataPath = fileMap.get(fmd5);
                                        String oldDataPath = localFilePath + ctrlDataPath;
                                        String lcN = ctrlDataPath.substring(ctrlDataPath.lastIndexOf("/") + 1, ctrlDataPath.length());
                                        String newDataPath = lcPath + lcN;
                                        JsonUtil.copyFile(oldDataPath, newDataPath);
                                        //双写多媒体库,并添加字段
//                                        uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                        lcMainFilePath = newDataPath;
                                        logger.info("no datafile match lcPath , and the new lcMainFilePath is " + lcMainFilePath);
//                                continue;
                                    }
                                    jsonObject.put("mmsFileUrl", fastPo.getFilePath());
                                    jsonObject.put("mmsFileShowUrl", fastPo.getFilePath());
                                    logger.info("mmsFileUrl mmsFileShowUrl put json end !!");
                                    logger.info("fileUrl fileShowUrl put json !!");
                                    logger.info("fileUrl fileShowUrl fileUrlmms fileShowUrlmms put json !!");
                                    jsonObject.put("fileUrl", lcMainFilePath);
                                    jsonObject.put("fileShowUrl", lcMainFilePath);
//                                    jsonObject.put("fileUrlmms", fastPo.getFilePath());
//                                    jsonObject.put("fileShowUrlmms", fastPo.getFilePath());
                                    logger.info("fileUrl fileShowUrl fileUrlmms fileShowUrlmms put json end !!");
                                } else {
                                    //没有样本文件，不拷贝龙存，不拼路径
                                    logger.info(fmd5 + " doesn't have datafile ,ane the containFile is " + containFile);
                                }
                            }//end handle record   
                        } else if (returndata.equals("orderInfo")) {
                            urls = orderUrlStr.split(";");
                            urlsN = orderUrlStrNo.split(";");
                            
                            JSONArray dataArray = ob.getJSONArray("record_list");
                            
                            if (dataArray.size() == 0) {
                                FJRThreadTask.errorFlag = 2;
                                flag = false;
                                logger.error(" data file count is 0 **************");
                                return flag;
                            }

//                    if (fDfsRetStrMap.size() == dataArray.size()) {
                            //把上传至FastDfs返回的map值插入到data下的json文件fileurl，fileicon中
//                        String lcPath = "/ybkdata/yb/";
                            for (int i = 0; i < dataArray.size(); i++) {
                                String lcPath = BanBkE2p.lcPathBase;
                                JSONObject orderJsonObject = dataArray.getJSONObject(i);
                                JSONObject jsonObject = null;
                                String dataType = "";
                                //指令数据
                                JSONArray orderlist = orderJsonObject.getJSONArray("orderSampleList");
                                for (int m = 0; m < orderlist.size(); m++) {
                                    jsonObject = orderlist.getJSONObject(m);
                                    dataType = jsonObject.get("typeName").toString();
                                    if (dataType == null || dataType.equals("")) {
                                        logger.info("typeName ------  does not exist");
                                        continue;
                                    }
                                    Date dt = new Date();
                                    SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
                                    String dataTime = matter1.format(dt);
                                    String fmd5 = jsonObject.get("fileMd5").toString();
                                    if (fmd5 == null || fmd5.equals("")) {
                                        logger.info("fileMd5 ------  does not exist");
                                        continue;
                                    }
                                    String containFile = "true";
                                    try {
                                        containFile = jsonObject.get("containFile").toString();
                                    } catch (Exception e) {
                                        logger.info("json fileMd5 is " + fmd5 + " doesn't have contailFile!!!" + e.getMessage(), e);
                                    }
                                    logger.info("json fileMd5 ------------: " + fmd5 + " ,and the containFile is " + containFile);
                                    lcPath = lcPath + dataType + "/" + dataTime + "/" + fmd5 + "/";
                                    Map<String, String> lcDfMap = new HashMap<String, String>();
                                    boolean attachFlag = true;
                                    JSONArray attachArray = null;
                                    try {
                                        attachArray = jsonObject.getJSONArray("attachmentList");
                                        if (attachArray.isEmpty() || attachArray.size() == 0 || attachArray == null) {
                                            logger.info("attachmentList no object !!!");
                                            attachFlag = false;
                                        } else {
                                            attachFlag = true;
                                        }
                                    } catch (Exception e) {
                                        logger.info("attachmentList no exist!!!" + e.getMessage(), e);
                                        attachFlag = false;
                                    }
                                    
                                    if (attachFlag) {
                                        for (int t = 0; t < attachArray.size(); t++) {
                                            JSONObject attachObject = attachArray.getJSONObject(t);
                                            if (attachObject.toJSONString().contains("fileMd5")) {
                                                
                                                String arrMd5 = attachObject.get("fileMd5").toString();
                                                if (arrMd5 == null || arrMd5.equals("")) {
                                                    logger.info("arrMd5 ------  does not exist");
                                                    continue;
                                                }
                                                FastPo attachfastPo = fDfsRetStrMap.get(attachObject.get("fileMd5").toString());
//                                    String lcSecPath = lcDfMap.get(attachObject.get("md5").toString());
                                                String ctrlDataPath = fileMap.get(attachObject.get("fileMd5").toString());
                                                String lcHalfPath = attachObject.get("relativePath").toString();
                                                if (lcHalfPath == null || lcHalfPath.equals("") || lcHalfPath.equals(" ")) {
                                                    lcHalfPath = attachObject.get("originFileName").toString();
                                                } else {
                                                    lcHalfPath = lcHalfPath.substring(lcHalfPath.indexOf("/") + 1, lcHalfPath.length());
                                                }
                                                String oldDataPath = localFilePath + ctrlDataPath;
                                                String newDataPath = lcPath + lcHalfPath;
                                                JsonUtil.copyFile(oldDataPath, newDataPath);
                                                //双写多媒体库,并添加字段
//                                            String uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                                //mmsAttachmentUrl
                                                attachObject.put("mmsAttachmentUrl", attachfastPo.getFilePath());
                                                attachObject.put("attachmentUrl", newDataPath);

//                                            String attachfpath = attachfastPo.getFilePath();
//                                            logger.info("attachfpath - " + attachfpath);
//                                            attachObject.put("location", newDataPath);
//                                            attachObject.put("mmslocation", attachfastPo.getFilePath());
                                                lcDfMap.put(attachObject.get("fileMd5").toString(), newDataPath);
                                                
                                            } else {
                                                //文件未来会推送过来
                                                logger.info("fileMd5 and fileName is not exist");
                                            }
                                        }
                                    }
                                    //处理主表字段
                                    FastPo fastPo = fDfsRetStrMap.get(jsonObject.get("fileMd5").toString());
                                    if (fastPo == null) {
                                        logger.info("no datafile match json -----------------------!!");
                                        continue;
                                    }
                                    if (containFile != "false") {
                                        String lcMainFilePath = lcDfMap.get(fmd5);
//                                        String uploadFile2Multimedia = "";
                                        if (lcMainFilePath == null) {
                                            logger.info("no datafile match lcPath -----------------------!!");
                                            String ctrlDataPath = fileMap.get(fmd5);
                                            String oldDataPath = localFilePath + ctrlDataPath;
                                            String lcN = ctrlDataPath.substring(ctrlDataPath.lastIndexOf("/") + 1, ctrlDataPath.length());
                                            String newDataPath = lcPath + lcN;
                                            JsonUtil.copyFile(oldDataPath, newDataPath);
                                            //双写多媒体库,并添加字段
//                                            uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                            lcMainFilePath = newDataPath;
//                                continue;
                                        }
                                        jsonObject.put("mmsFileUrl", fastPo.getFilePath());
                                        jsonObject.put("mmsFileShowUrl", fastPo.getFilePath());
                                        logger.info("mmsFileUrl mmsFileShowUrl put json end !!");
                                        logger.info("fileUrl fileShowUrl put json !!");
                                        logger.info("fileUrl fileShowUrl fileUrlmms fileShowUrlmms put json !!");
                                        jsonObject.put("fileUrl", lcMainFilePath);
                                        jsonObject.put("fileShowUrl", lcMainFilePath);
//                                        jsonObject.put("fileUrlmms", fastPo.getFilePath());
//                                        jsonObject.put("fileShowUrlmms", fastPo.getFilePath());
                                        logger.info("fileUrl fileShowUrl fileUrlmms fileShowUrlmms put json end !!");
                                    } else {
                                        //没有样本文件，不拷贝龙存，不拼路径
                                        logger.info(fmd5 + " doesn't have datafile ,ane the containFile is " + containFile);
                                    }
                                }//end handle record  
                                //指令附件
                                JSONArray orderAttachArray = null;
                                boolean orderAttachFlag = true;
                                try {
                                    orderAttachArray = orderJsonObject.getJSONArray("attachmentList");
                                    if (orderAttachArray.isEmpty() || orderAttachArray.size() == 0 || orderAttachArray == null) {
                                        logger.info("orderAttachmentList no object !!!");
                                        orderAttachFlag = false;
                                    } else {
                                        orderAttachFlag = true;
                                    }
                                } catch (Exception e) {
                                    logger.info("orderAttachmentList no exist!!!" + e.getMessage(), e);
                                    orderAttachFlag = false;
                                }
                                
                                if (orderAttachFlag) {
                                    for (int t = 0; t < orderAttachArray.size(); t++) {
                                        JSONObject attachObject = orderAttachArray.getJSONObject(t);
                                        String arrMd5 = attachObject.get("fileMd5").toString();
                                        FastPo attachfastPo = fDfsRetStrMap.get(attachObject.get("fileMd5").toString());
                                        String arrfilename = attachObject.get("fileName").toString();
                                        String ctrlDataPath = fileMap.get(arrMd5);
                                        if (arrMd5 == null || arrMd5.equals("")) {
                                            logger.info("arrMd5 ------  does not exist");
                                            continue;
                                        }
                                        String oldDataPath = localFilePath + ctrlDataPath;
                                        String newDataPath = "/ybkdata/order/" + currenttime + "/" + arrMd5 + "/" + arrfilename;
                                        logger.info(arrMd5 + " begin to copy lc!!!");
                                        JsonUtil.copyFile(oldDataPath, newDataPath);
                                        //双写多媒体库,并添加字段
//                                        String uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                        //mmsAttachmentUrl
                                        attachObject.put("mmsAttachmentUrl", attachfastPo.getFilePath());
                                        attachObject.put("attachmentUrl", newDataPath);
//                                        String attachfpath = attachfastPo.getFilePath();
//                                        logger.info("attachfpath - " + attachfpath);
//                                        attachObject.put("mmslocation", attachfpath);
                                    }
                                }
                            }
                            
                        }
                    }// end if (flag ) ** if bad data
                    String lastJ = ob.toString();
                    logger.debug("last json !!! ----------- " + lastJ);

                    //修改本地文件
                    File file = new File(jsonFilePath);
                    if (file.exists()) {
                        file.delete();
                    } else {
                        file.createNewFile();
                    }
                    FileWriter fileWriter = new FileWriter(jsonFilePath);
                    fileWriter.write(lastJ);
                    fileWriter.flush();
                    fileWriter.close();
                    
                    while (true) {
                        int stat = 0;
                        for (int i = 0; i < urls.length; i++) {
//                            stat = JsonUtil.httpPost(urls[i], lastJ, true);
                            stat = JsonUtil.httpPost(urls[i], file);
                            if (stat == 200) {
                                logger.info("json send url " + urls[i] + " send ok !!!");
                                break;
                            }
                        }
                        Thread.sleep(5000);
                        if (stat == 200) {
                            logger.info("json send ok !!!");
                            break;
                        }
                    }
                }//end handle json file
            }
            
            logger.info(" JsonUtil end " + df.format(new Date()));
        } catch (Exception ex) {
            FJRThreadTask.errorFlag = 1;
            flag = false;
            logger.error(" parse jsonfile error !!!!!!!! " + ex.getMessage(), ex);
        }
        return flag;
    }
        public static void main(String[] args) {
        String jsonFilePath="205_20171017_aa648c97-2041-4b66-bc9c-ff4f16f5bd75.json";
//        String jsonFilePath="205_20171017_ec22aa87-2a8a-4a46-a9b4-47dbf9281148.json";
//        String jsonFilePath = "205_20171017_ddf806cf-e226-4701-b13d-68ad183c85ea.json";
        JsonUtil jsonUtil = new JsonUtil();
        String JsonContext = jsonUtil.ReadFile(jsonFilePath);
        JSONObject ob = JSONObject.parseObject(JsonContext);
        System.out.println("length"+ob.toString().length());
        System.out.println("start look======================" + ob.toString());
    }
    public static boolean jsonDataLc(String localFilePath, List<Map<String, String>> dataFileList, String src) {
        boolean flag = true;
        String[] urls = null;//请求霍亚宁接口url
        String[] urlsN = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String currenttime = sdf.format(new Date());
        long start = System.currentTimeMillis();
        try {
            
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            logger.info(" JsonUtil start " + df.format(new Date()));
            List<String> jsonFileList = new ArrayList<String>();
            Map<String, String> fileMap = new HashMap<String, String>();
            for (int i = 0; i < dataFileList.size(); i++) {
                Map<String, String> str = dataFileList.get(i);
                String lastFilename = str.get("name");
                String realName = lastFilename.substring(lastFilename.lastIndexOf("/") + 1, lastFilename.length());
                String dataFileName = localFilePath + lastFilename;
                String okFileName = localFilePath + lastFilename + ".ok";
                File dataf = new File(dataFileName);
                File okf = new File(okFileName);
                if (dataf.exists()) {
                    if (realName.endsWith(".json")) {
                        jsonFileList.add(lastFilename);
                    } else {
                        String md5N = realName.substring(0, realName.lastIndexOf("."));
                        fileMap.put(md5N, lastFilename);
                    }
                }
            }
            long JsonUtiltime = System.currentTimeMillis();
            logger.info("JsonUtil end use time " + (JsonUtiltime - start) + " ms");
            if (jsonFileList.size() == 0) {
                FJRThreadTask.errorFlag = 1;
                flag = false;
                logger.error(" JSON file does not exist");
                return flag;
            }
            
            if (fileMap.size() == 0 || fileMap.isEmpty()) {
                for (int k = 0; k < jsonFileList.size(); k++) {
                    String JsonContext = null;
                    JSONObject ob = null;
                    String jsonFilePath = null;
                    if (flag) {
                        
                        jsonFilePath = localFilePath + jsonFileList.get(k);
//                    jsonFilePath = "/home/wmr/NetBeansProjects/datatest/LoadSample.json";
                        logger.info(" Get JSON file path: " + jsonFilePath + "   " + df.format(new Date()));
                        //读取json文件内容
                        JsonUtil jsonUtil = new JsonUtil();
//                    String JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        if (JsonContext == null) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("failed to get JSON string");
                            return flag;
                        } else {
                            logger.debug(" JsonContext -------- " + JsonContext);
                            //解析dataType接口类型
                            try {
                                ob = JSONObject.parseObject(JsonContext);
                            } catch (Exception e) {
                                FJRThreadTask.errorFlag = 1;
                                flag = false;
                                logger.error(" JSON file error" + e.getMessage(), e);
                                return flag;
                            }

                            //获得并处理每条记录
                            String returndata = ob.get("dataType").toString();
                            if (returndata == null || returndata.isEmpty()) {
                                FJRThreadTask.errorFlag = 1;
                                flag = false;
                                logger.error("get dataType failed **************");
                                return flag;
                            } else if (returndata.equals("userInfo")) {
                                urls = userUrlStr.split(";");
                                urlsN = userUrlStrNo.split(";");
                            } else if (returndata.equals("sampleInfo")) {
                                urls = sampleUrlStr.split(";");
                                urlsN = sampleUrlStrNo.split(";");
                            } else if (returndata.equals("orderInfo")) {
                                urls = orderUrlStr.split(";");
                                urlsN = orderUrlStrNo.split(";");
                            }
                        }
                        
                    }// end if (flag ) ** if bad data
                    //解析datattype，处理记录
                    long begin = System.currentTimeMillis();
                    logger.info("anaylys dataType use time " + (begin - JsonUtiltime) + " ms");
                    while (true) {
                        long end = System.currentTimeMillis();
                        long middle = (end - begin) / 1000;
                        long tmpTimeout = Long.parseLong(sendTimeout);
                        if (middle < tmpTimeout) {
                            logger.info(" runtime: " + middle + "  timeout: " + sendTimeout);
//                            Thread.sleep(3000);
                        } else {
                            logger.error(" http send is killed, because of timeout!");
                            flag = false;
                            break;
                        }
                        
                        int stat = 0;
                        int urlslength = urlsN.length;
                        int random = (int) (Math.random() * urlslength);
                        
                        stat = JsonUtil.httpPost(urlsN[random], new File(jsonFilePath));
                        if (stat == 200) {
                            logger.info("json send urlN " + urlsN[random] + " send ok !!!");
                            break;
                        } else {
//                            //20次啊20次
//                            int count = 0;
//                            while (count < 20) {
////                                int random = (int) (Math.random() * urlsN.length);
//                                logger.info("json send urlN random:" + random + ",url = " + urls[random]);
//                                stat = JsonUtil.httpPost(urlsN[random], new File(jsonFilePath));
//                                if (stat == 200) {
//                                    logger.info("json send url " + urlsN[random] + " send ok !!!");
//                                    break;
//                                }
//                                count++;
//                            }
                        }

//                        for (int i = 0; i < urlsN.length; i++) {
////                            stat = JsonUtil.httpPost(urlsN[i], JsonContext, true);
//                            stat = JsonUtil.httpPost(urlsN[i], new File(jsonFilePath));
//                            if (stat == 200) {
////                                logger.info("json send ok !!!");
//                                logger.info("json send urlN " + urlsN[i] + " send ok !!!");
//                                break;
//                            }
//                        }
                        Thread.sleep(1000);
//                        if (stat == 200) {
//                            logger.info("json send ok !!!");
//                            break;
//                        }
                    }
                }//end handle json file
            } else {
                //处理每个文件
                //没有数据文件
                for (int k = 0; k < jsonFileList.size(); k++) {
                    String JsonContext = null;
                    JSONObject ob = null;
                    String jsonFilePath = null;
                    if (flag) {
                        
                        jsonFilePath = localFilePath + jsonFileList.get(k);
//                    jsonFilePath = "/home/wmr/NetBeansProjects/datatest/LoadSample.json";
                        logger.info(" Get JSON file path: " + jsonFilePath + "   " + df.format(new Date()));
                        //读取json文件内容
                        JsonUtil jsonUtil = new JsonUtil();
//                    String JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        if (JsonContext == null) {
                            
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("failed to get JSON string");
                            return flag;
                        }
                        try {
                            logger.info("JsonContext = "+JsonContext);
                            ob = JSONObject.parseObject(JsonContext);
                            logger.info("start look======================" + ob.toString());
                        } catch (Exception e) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error(" JSON file error" + e.getMessage(), e);
                            return flag;
                        }

                        //获得并处理每条记录
                        String returndata = ob.get("dataType").toString();
                        if (returndata == null || returndata.isEmpty()) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("get dataType failed **************");
                            return flag;
                        } else if (returndata.equals("userInfo")) {
                            //用户接口
                            urls = userUrlStr.split(";");
                            urlsN = userUrlStrNo.split(";");
                            
                            JSONArray dataArray = ob.getJSONArray("record_list");
                            if (dataArray.size() == 0) {
                                FJRThreadTask.errorFlag = 2;
                                flag = false;
                                logger.error(" data file count is 0 **************");
                                return flag;
                            }
                            
                            for (int i = 0; i < dataArray.size(); i++) {
                                String lcPath = BanBkE2p.lcPathBase;
                                JSONObject jsonObject = dataArray.getJSONObject(i);
                                jsonObject.put("sourceSystemCode", src);
                                String dataType = dataType = jsonObject.get("typeName").toString();
                                
                                if (dataType == null || dataType.equals("")) {
                                    logger.info("typeName ------  does not exist");
                                    continue;
                                }
                                Date dt = new Date();
                                SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
                                String dataTime = matter1.format(dt);
                                String fmd5 = jsonObject.get("fileMd5").toString();
                                if (fmd5 == null || fmd5.equals("")) {
                                    logger.info("fileMd5 ------  does not exist");
                                    continue;
                                }
                                logger.info("json fileMd5 ------------: " + fmd5);
                                lcPath = lcPath + dataType + "/" + dataTime + "/" + fmd5 + "/";
                                Map<String, String> lcDfMap = new HashMap<String, String>();
                                boolean attachFlag = true;
                                JSONArray attachArray = null;
                                try {
                                    attachArray = jsonObject.getJSONArray("attachmentList");
                                    if (attachArray.isEmpty() || attachArray.size() == 0 || attachArray == null) {
                                        logger.info("attachmentList no object !!!");
                                        attachFlag = false;
                                    } else {
                                        attachFlag = true;
                                    }
                                } catch (Exception e) {
                                    logger.info("attachmentList no exist!!!" + e.getMessage(), e);
                                    attachFlag = false;
                                }
                                
                                if (attachFlag) {
                                    for (int t = 0; t < attachArray.size(); t++) {
                                        JSONObject attachObject = attachArray.getJSONObject(t);
                                        String arrMd5 = attachObject.get("fileMd5").toString();
                                        if (arrMd5 == null || arrMd5.equals("")) {
                                            logger.info("arrMd5 ------  does not exist");
                                            continue;
                                        }
                                        String ctrlDataPath = fileMap.get(attachObject.get("fileMd5").toString());
                                        String lcHalfPath = attachObject.get("relativePath").toString();
                                        if (lcHalfPath == null || lcHalfPath.equals("") || lcHalfPath.equals(" ")) {
                                            lcHalfPath = attachObject.get("originalFileName").toString();
                                        } else {
                                            lcHalfPath = lcHalfPath.substring(lcHalfPath.indexOf("/") + 1, lcHalfPath.length());
                                        }
                                        String oldDataPath = localFilePath + ctrlDataPath;
                                        String newDataPath = lcPath + lcHalfPath;
                                        JsonUtil.copyFile(oldDataPath, newDataPath);
                                        attachObject.put("attachmentUrl", newDataPath);
                                        lcDfMap.put(attachObject.get("fileMd5").toString(), newDataPath);
                                    }
                                }
                                String lcMainFilePath = lcDfMap.get(fmd5);
                                if (lcMainFilePath == null) {
                                    logger.info("no datafile match lcPath -----------------------!!");
                                    String ctrlDataPath = fileMap.get(fmd5);
                                    String oldDataPath = localFilePath + ctrlDataPath;
                                    String lcN = ctrlDataPath.substring(ctrlDataPath.lastIndexOf("/") + 1, ctrlDataPath.length());
                                    String newDataPath = lcPath + lcN;
                                    JsonUtil.copyFile(oldDataPath, newDataPath);
                                    lcMainFilePath = newDataPath;
                                }
                                logger.info("fileUrl fileShowUrl mmsFileUrl mmsFileShowUrl put json !!");
                                jsonObject.put("fileUrl", lcMainFilePath);
                                jsonObject.put("fileShowUrl", lcMainFilePath);
                                logger.info("fileUrl fileShowUrl mmsFileUrl mmsFileShowUrl put json end !!");
                                
                            }
                            long begin = System.currentTimeMillis();
                            logger.info("json fileMd5 use time " + (begin - JsonUtiltime) + " ms");
                            
                        } else if (returndata.equals("sampleInfo")) {
                            //样本接口
                            urls = sampleUrlStr.split(";");
                            urlsN = sampleUrlStrNo.split(";");
                            
                            JSONArray dataArray = ob.getJSONArray("record_list");
                            if (dataArray.size() == 0) {
                                FJRThreadTask.errorFlag = 2;
                                flag = false;
                                logger.error(" data file count is 0 **************");
                                return flag;
                            }
                            
                            for (int i = 0; i < dataArray.size(); i++) {
                                String lcPath = BanBkE2p.lcPathBase;
                                JSONObject jsonObject = dataArray.getJSONObject(i);
                                String dataType = dataType = jsonObject.get("typeName").toString();
                                
                                if (dataType == null || dataType.equals("")) {
                                    logger.info("typeName ------  does not exist");
                                    continue;
                                }
                                Date dt = new Date();
                                SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
                                String dataTime = matter1.format(dt);
                                String fmd5 = jsonObject.get("fileMd5").toString();
                                if (fmd5 == null || fmd5.equals("")) {
                                    logger.info("fileMd5 ------  does not exist");
                                    continue;
                                }
                                String containFile = "true";
                                try {
                                    containFile = jsonObject.get("containFile").toString();
                                } catch (Exception e) {
                                    logger.info("json fileMd5 is " + fmd5 + " doesn't have contailFile!!!" + e.getMessage(), e);
                                }
                                
                                logger.info("json fileMd5 ------------: " + fmd5 + " ,and the containFile is " + containFile);
                                lcPath = lcPath + dataType + "/" + dataTime + "/" + fmd5 + "/";
                                Map<String, String> lcDfMap = new HashMap<String, String>();
                                boolean attachFlag = true;
                                JSONArray attachArray = null;
                                try {
                                    attachArray = jsonObject.getJSONArray("attachmentList");
                                    if (attachArray.isEmpty() || attachArray.size() == 0 || attachArray == null) {
                                        logger.info("attachmentList no object !!!");
                                        attachFlag = false;
                                    } else {
                                        attachFlag = true;
                                    }
                                } catch (Exception e) {
                                    logger.info("attachmentList no exist!!!" + e.getMessage(), e);
                                    attachFlag = false;
                                }
                                
                                if (attachFlag) {
                                    for (int t = 0; t < attachArray.size(); t++) {
                                        
                                        JSONObject attachObject = attachArray.getJSONObject(t);
                                        logger.info("attachArray size = " + attachArray.size() + ",attachObject  toJSONString = " + attachObject.toJSONString());
                                        //判断是否含有fileMd5字段和fileName
                                        if (attachObject.toJSONString().contains("fileMd5")) {
                                            
                                            String arrMd5 = attachObject.get("fileMd5").toString();
                                            if (arrMd5 == null || arrMd5.equals("") || arrMd5.equals("null")) {
                                                logger.info("arrMd5 ------  does not exist");
                                                continue;
                                            }
                                            try {
                                                
                                                String ctrlDataPath = fileMap.get(attachObject.get("fileMd5").toString());
                                                String lcHalfPath = attachObject.get("relativePath").toString();
                                                if (lcHalfPath == null || lcHalfPath.equals("") || lcHalfPath.equals(" ")) {
                                                    lcHalfPath = attachObject.get("originalFileName").toString();
                                                } else {
                                                    lcHalfPath = lcHalfPath.substring(lcHalfPath.indexOf("/") + 1, lcHalfPath.length());
                                                }
                                                String oldDataPath = localFilePath + ctrlDataPath;
                                                String newDataPath = lcPath + lcHalfPath;
                                                logger.info(arrMd5 + " begin to copy lc!!!");
                                                JsonUtil.copyFile(oldDataPath, newDataPath);
                                                //双写多媒体库,并添加字段
                                                String returnKey = uploadFile2Multimedia(oldDataPath);
//                                            String returnKey="";
                                                //mmsAttachmentUrl
                                                attachObject.put("mmsAttachmentUrl", returnKey);
                                                attachObject.put("attachmentUrl", newDataPath);
                                                lcDfMap.put(attachObject.get("fileMd5").toString(), newDataPath);
                                            } catch (Exception e) {
                                                logger.error("fileMd5 " + arrMd5 +",relativePath "+attachObject.get("relativePath").toString()+ " copy errpr !" + e.getMessage(), e);
                                            }
                                        } else {
                                            //文件未来会推送过来
                                            logger.info("fileMd5 and fileName is not exist");
                                        }
                                    }
                                }
                                if (containFile != "false") {
                                    String lcMainFilePath = lcDfMap.get(fmd5);
                                    String uploadFile2Multimedia = "";
                                    String ctrlDataPath = "";
                                    if (lcMainFilePath == null) {
                                        logger.info("no datafile match lcPath -----------------------!!");
                                        try {
                                            ctrlDataPath = fileMap.get(fmd5);
                                            String oldDataPath = localFilePath + ctrlDataPath;
                                            String lcN = ctrlDataPath.substring(ctrlDataPath.lastIndexOf("/") + 1, ctrlDataPath.length());
                                            String newDataPath = lcPath + lcN;
                                            JsonUtil.copyFile(oldDataPath, newDataPath);
                                            //双写多媒体库,并添加字段
                                            uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                            //mmsFileUrl,mmsFileShowUrl
                                            lcMainFilePath = newDataPath;
                                        } catch (Exception e) {
                                            logger.error("local copy error! get filemd5 error." + e.getMessage(), e);
                                        }
                                        logger.info("no datafile match lcPath = " + lcPath + " , and the new lcMainFilePath is " + lcMainFilePath);
                                    }
                                    jsonObject.put("mmsFileUrl", uploadFile2Multimedia);
                                    jsonObject.put("mmsFileShowUrl", uploadFile2Multimedia);
                                    logger.info("mmsFileUrl mmsFileShowUrl put json end !!");
                                    logger.info("fileUrl fileShowUrl put json !!");
                                    jsonObject.put("fileUrl", lcMainFilePath);
                                    jsonObject.put("fileShowUrl", lcMainFilePath);
                                    logger.info("fileUrl fileShowUrl put json end !!"+jsonObject.toJSONString());
                                } else {
                                    //没有样本文件，不拷贝龙存，不拼路径
                                    logger.info(fmd5 + " doesn't have datafile ,ane the containFile is " + containFile);
                                }
                            }
                            long begin = System.currentTimeMillis();
                            logger.info("sampleInfo use time " + (begin - JsonUtiltime) + " ms");
                        } else if (returndata.equals("orderInfo")) {
                            urls = orderUrlStr.split(";");
                            urlsN = orderUrlStrNo.split(";");
                            
                            JSONArray dataArray = ob.getJSONArray("record_list");
                            if (dataArray.size() == 0) {
                                FJRThreadTask.errorFlag = 2;
                                flag = false;
                                logger.error(" data file count is 0 **************");
                                return flag;
                            }
                            for (int i = 0; i < dataArray.size(); i++) {
                                String lcPath = BanBkE2p.lcPathBase;
                                JSONObject orderJsonObject = dataArray.getJSONObject(i);
                                JSONObject jsonObject = null;
                                String dataType = "";
                                //指令数据
                                JSONArray orderlist = orderJsonObject.getJSONArray("orderSampleList");
                                for (int m = 0; m < orderlist.size(); m++) {
                                    jsonObject = orderlist.getJSONObject(m);
                                    dataType = jsonObject.get("typeName").toString();
                                    
                                    if (dataType == null || dataType.equals("")) {
                                        logger.info("typeName ------  does not exist");
                                        continue;
                                    }
                                    Date dt = new Date();
                                    SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
                                    String dataTime = matter1.format(dt);
                                    String fmd5 = jsonObject.get("fileMd5").toString();
                                    if (fmd5 == null || fmd5.equals("")) {
                                        logger.info("fileMd5 ------  does not exist");
                                        continue;
                                    }
                                    String containFile = "true";
                                    try {
                                        containFile = jsonObject.get("containFile").toString();
                                    } catch (Exception e) {
                                        logger.info("json fileMd5 is " + fmd5 + " doesn't have contailFile!!!" + e.getMessage(), e);
                                    }
                                    
                                    logger.info("json fileMd5 ------------: " + fmd5 + " ,and the containFile is " + containFile);
                                    lcPath = lcPath + dataType + "/" + dataTime + "/" + fmd5 + "/";
                                    Map<String, String> lcDfMap = new HashMap<String, String>();
                                    boolean attachFlag = true;
                                    JSONArray attachArray = null;
                                    try {
                                        attachArray = jsonObject.getJSONArray("attachmentList");
                                        if (attachArray.isEmpty() || attachArray.size() == 0 || attachArray == null) {
                                            logger.info("attachmentList no object !!!");
                                            attachFlag = false;
                                        } else {
                                            attachFlag = true;
                                        }
                                    } catch (Exception e) {
                                        logger.info("attachmentList no exist!!!" + e.getMessage(), e);
                                        attachFlag = false;
                                    }
                                    
                                    if (attachFlag) {
                                        for (int t = 0; t < attachArray.size(); t++) {
                                            JSONObject attachObject = attachArray.getJSONObject(t);
                                            if (attachObject.toJSONString().contains("fileMd5")) {
                                                String arrMd5 = attachObject.get("fileMd5").toString();
                                                if (arrMd5 == null || arrMd5.equals("")) {
                                                    logger.info("arrMd5 ------  does not exist");
                                                    continue;
                                                }
                                                String ctrlDataPath = fileMap.get(attachObject.get("fileMd5").toString());
                                                String lcHalfPath = attachObject.get("relativePath").toString();
                                                if (lcHalfPath == null || lcHalfPath.equals("") || lcHalfPath.equals(" ")) {
                                                    lcHalfPath = attachObject.get("originalFileName").toString();
                                                } else {
                                                    lcHalfPath = lcHalfPath.substring(lcHalfPath.indexOf("/") + 1, lcHalfPath.length());
                                                }
                                                String oldDataPath = localFilePath + ctrlDataPath;
                                                String newDataPath = lcPath + lcHalfPath;
                                                logger.info(arrMd5 + " begin to copy lc!!!");
                                                JsonUtil.copyFile(oldDataPath, newDataPath);
                                                //双写多媒体库,并添加字段
                                                String uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                                //mmsAttachmentUrl
                                                attachObject.put("mmsAttachmentUrl", uploadFile2Multimedia);
                                                attachObject.put("attachmentUrl", newDataPath);
                                                lcDfMap.put(attachObject.get("fileMd5").toString(), newDataPath);
                                            } else {
                                                //文件未来会推送过来
                                                logger.info("fileMd5 and fileName is not exist");
                                            }
                                        }
                                    }
                                    
                                    if (containFile != "false") {
                                        String lcMainFilePath = lcDfMap.get(fmd5);
                                        String uploadFile2Multimedia = "";
                                        String ctrlDataPath = "";
                                        if (lcMainFilePath == null) {
                                            logger.info("no datafile match lcPath -----------------------!!");
                                            try {
                                                ctrlDataPath = fileMap.get(fmd5);
                                                String oldDataPath = localFilePath + ctrlDataPath;
                                                String lcN = ctrlDataPath.substring(ctrlDataPath.lastIndexOf("/") + 1, ctrlDataPath.length());
                                                String newDataPath = lcPath + lcN;
                                                JsonUtil.copyFile(oldDataPath, newDataPath);
                                                //双写多媒体库,并添加字段
                                                uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                                //mmsFileUrl,mmsFileShowUrl
                                                lcMainFilePath = newDataPath;
                                            } catch (Exception e) {
                                                logger.error("local copy error! get filemd5 error." + e.getMessage(), e);
                                            }
                                        }
                                        jsonObject.put("mmsFileUrl", uploadFile2Multimedia);
                                        jsonObject.put("mmsFileShowUrl", uploadFile2Multimedia);
                                        logger.info("mmsFileUrl mmsFileShowUrl put json end !!");
                                        logger.info("fileUrl fileShowUrl put json !!");
                                        jsonObject.put("fileUrl", lcMainFilePath);
                                        jsonObject.put("fileShowUrl", lcMainFilePath);
                                        logger.info("fileUrl fileShowUrl put json end !!");
                                    } else {
                                        //没有样本文件，不拷贝龙存，不拼路径
                                        logger.info(fmd5 + " doesn't have datafile ,ane the containFile is " + containFile);
                                    }
                                }

                                //指令附件
                                JSONArray orderAttachArray = null;
                                boolean orderAttachFlag = true;
                                try {
                                    orderAttachArray = orderJsonObject.getJSONArray("attachmentList");
                                    if (orderAttachArray.isEmpty() || orderAttachArray.size() == 0 || orderAttachArray == null) {
                                        logger.info("orderAttachmentList no object !!!");
                                        orderAttachFlag = false;
                                    } else {
                                        orderAttachFlag = true;
                                    }
                                } catch (Exception e) {
                                    logger.info("orderAttachmentList no exist!!!" + e.getMessage(), e);
                                    orderAttachFlag = false;
                                }
                                
                                if (orderAttachFlag) {
                                    for (int t = 0; t < orderAttachArray.size(); t++) {
                                        JSONObject attachObject = orderAttachArray.getJSONObject(t);
                                        String arrMd5 = attachObject.get("fileMd5").toString();
                                        String arrfilename = attachObject.get("fileName").toString();
                                        String ctrlDataPath = fileMap.get(arrMd5);
                                        if (arrMd5 == null || arrMd5.equals("")) {
                                            logger.info("arrMd5 ------  does not exist");
                                            continue;
                                        }
                                        String oldDataPath = localFilePath + ctrlDataPath;
                                        String newDataPath = "/ybkdata/order/" + currenttime + "/" + arrMd5 + "/" + arrfilename;
                                        logger.info(arrMd5 + " begin to copy lc!!!");
                                        JsonUtil.copyFile(oldDataPath, newDataPath);
                                        //双写多媒体库,并添加字段
                                        String uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                        //mmsAttachmentUrl
                                        attachObject.put("mmsAttachmentUrl", uploadFile2Multimedia);
                                        attachObject.put("attachmentUrl", newDataPath);
                                    }
                                }
                            }
                            long begin = System.currentTimeMillis();
                            logger.info("copy lc use time " + (begin - JsonUtiltime) + " ms");
                            
                        }

                        //end handle record   
                    }// end if (flag ) ** if bad data

                    String lastJ = ob.toString();
                    logger.info("Parser json finish!!! ----------- "+ob.toJSONString());

                    //修改本地文件
                    File file = new File(jsonFilePath);
                    if (file.exists()) {
                        file.delete();
                    } else {
                        file.createNewFile();
                    }
                    FileWriter fileWriter = new FileWriter(jsonFilePath);
                    fileWriter.write(lastJ);
                    fileWriter.flush();
                    fileWriter.close();
                    long begin = System.currentTimeMillis();
                    logger.info("BBBBBBBBBBBBegin to send " + jsonFilePath);
                    while (true) {
                        long end = System.currentTimeMillis();
                        long middle = (end - begin) / 1000;
                        long tmpTimeout = Long.parseLong(sendTimeout);
                        if (middle < tmpTimeout) {
                            logger.info(" runtime: " + middle + "  timeout: " + sendTimeout);
//                            Thread.sleep(3000);
                        } else {
                            logger.error(" http send is killed, because of timeout!");
                            flag = false;
                            break;
                        }
                        int stat = 0;
                        int urlslength = urlsN.length;
                        int random = (int) (Math.random() * urlslength);
                        
                        stat = JsonUtil.httpPost(urlsN[random], new File(jsonFilePath));
                        if (stat == 200) {
                            logger.info("json send urlN " + urlsN[random] + " send ok !!!" + "and use time " + (System.currentTimeMillis() - begin) + " ms");
                            break;
                        } else {
//                            //20次啊20次
//                            int count = 0;
//                            while (count < 20) {
////                                int random = (int) (Math.random() * urlsN.length);
//                                logger.info("json send urlN random:" + random + ",url = " + urls[random]);
//                                stat = JsonUtil.httpPost(urlsN[random], new File(jsonFilePath));
//                                if (stat == 200) {
//                                    logger.info("json send url " + urlsN[random] + " send ok !!!");
//                                    break;
//                                }
//                                count++;
//                            }
                        }
                        
                        Thread.sleep(100);
                    }
                    logger.info("json send ok, and use time " + (System.currentTimeMillis() - begin) + " ms");
                }//end handle json file
            }
            logger.info(" JsonUtil end " + df.format(new Date()));
        } catch (Exception ex) {
            FJRThreadTask.errorFlag = 1;
            flag = false;
            logger.error(" parse jsonfile error !!!!!!!! " + ex.getMessage(), ex);
        }
        return flag;
    }
    
    public static boolean jsonDataNo(String localFilePath, List<Map<String, String>> dataFileList, String src) {
        boolean flag = true;
        String[] urls = null;//请求霍亚宁接口url
        String[] urlsN = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String currenttime = sdf.format(new Date());
        try {
            
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            logger.info(" JsonUtil start " + df.format(new Date()));
            List<String> jsonFileList = new ArrayList<String>();
            Map<String, String> fileMap = new HashMap<String, String>();
            for (int i = 0; i < dataFileList.size(); i++) {
                Map<String, String> str = dataFileList.get(i);
                String lastFilename = str.get("name");
                String realName = lastFilename.substring(lastFilename.lastIndexOf("/") + 1, lastFilename.length());
                String dataFileName = localFilePath + lastFilename;
                String okFileName = localFilePath + lastFilename + ".ok";
                File dataf = new File(dataFileName);
                File okf = new File(okFileName);
                if (dataf.exists()) {
                    if (realName.endsWith(".json")) {
                        jsonFileList.add(lastFilename);
                    } else {
                        String md5N = realName.substring(0, realName.lastIndexOf("."));
                        fileMap.put(md5N, lastFilename);
                    }
                }
            }
            
            if (jsonFileList.size() == 0) {
                FJRThreadTask.errorFlag = 1;
                flag = false;
                logger.error(" JSON file does not exist");
                return flag;
            }
            
            if (fileMap.size() == 0 || fileMap.isEmpty()) {
                for (int k = 0; k < jsonFileList.size(); k++) {
                    String JsonContext = null;
                    JSONObject ob = null;
                    String jsonFilePath = null;
                    if (flag) {
                        
                        jsonFilePath = localFilePath + jsonFileList.get(k);
//                    jsonFilePath = "/home/wmr/NetBeansProjects/datatest/LoadSample.json";
                        logger.info(" Get JSON file path: " + jsonFilePath + "   " + df.format(new Date()));
                        //读取json文件内容
                        JsonUtil jsonUtil = new JsonUtil();
//                    String JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        if (JsonContext == null) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("failed to get JSON string");
                            return flag;
                        } else {
                            logger.debug(" JsonContext -------- " + JsonContext);
                            //解析dataType接口类型
                            try {
                                ob = JSONObject.parseObject(JsonContext);
                            } catch (Exception e) {
                                FJRThreadTask.errorFlag = 1;
                                flag = false;
                                logger.error(" JSON file error" + e.getMessage(), e);
                                return flag;
                            }

                            //获得并处理每条记录
                            String returndata = ob.get("dataType").toString();
                            if (returndata == null || returndata.isEmpty()) {
                                FJRThreadTask.errorFlag = 1;
                                flag = false;
                                logger.error("get dataType failed **************");
                                return flag;
                            } else if (returndata.equals("userInfo")) {
                                urls = userUrlStr.split(";");
                                urlsN = userUrlStrNo.split(";");
                            } else if (returndata.equals("sampleInfo")) {
                                urls = sampleUrlStr.split(";");
                                urlsN = sampleUrlStrNo.split(";");
                            } else if (returndata.equals("orderInfo")) {
                                urls = orderUrlStr.split(";");
                                urlsN = orderUrlStrNo.split(";");
                            }
                        }
                        
                    }// end if (flag ) ** if bad data
                    long begin = System.currentTimeMillis();
                    while (true) {
                        long end = System.currentTimeMillis();
                        long middle = (end - begin) / 1000;
                        long tmpTimeout = Long.parseLong(sendTimeout);
                        if (middle < tmpTimeout) {
                            logger.info(" runtime: " + middle + "  timeout: " + sendTimeout);
//                            Thread.sleep(3000);
                        } else {
                            logger.error(" http send is killed, because of timeout!");
                            flag = false;
                            break;
                        }
                        
                        int stat = 0;
                        for (int i = 0; i < urlsN.length; i++) {
//                            stat = JsonUtil.httpPost(urlsN[i], JsonContext, true);
                            stat = JsonUtil.httpPost(urlsN[i], new File(jsonFilePath));
                            if (stat == 200) {
//                                logger.info("json send ok !!!");
                                logger.info("json send urlN " + urlsN[i] + " send ok !!!");
                                break;
                            } else {
                                //20次啊20次
//                                int count = 0;
//                                while (count < 20) {
//                                    int random = (int) (Math.random() * urlsN.length);
//                                    logger.info("json send urlN i:" + i + ",url = " + urls[i]);
//                                    stat = JsonUtil.httpPost(urlsN[i], new File(jsonFilePath));
//                                    if (stat == 200) {
//                                        logger.info("json send url " + urlsN[i] + " send ok !!!");
//                                        break;
//                                    }
//                                    count++;
//                                }
                            }
                        }
                        Thread.sleep(5000);
                        if (stat == 200) {
                            logger.info("json send ok !!!");
                            break;
                        }
                    }
                }//end handle json file
            } else {
                //处理每个文件
                //没有数据文件
                for (int k = 0; k < jsonFileList.size(); k++) {
                    String JsonContext = null;
                    JSONObject ob = null;
                    String jsonFilePath = null;
                    if (flag) {
                        
                        jsonFilePath = localFilePath + jsonFileList.get(k);
//                    jsonFilePath = "/home/wmr/NetBeansProjects/datatest/LoadSample.json";
                        logger.info(" Get JSON file path: " + jsonFilePath + "   " + df.format(new Date()));
                        //读取json文件内容
                        JsonUtil jsonUtil = new JsonUtil();
//                    String JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        JsonContext = jsonUtil.ReadFile(jsonFilePath);
                        if (JsonContext == null) {
                            
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("failed to get JSON string");
                            return flag;
                        }
                        try {
                            ob = JSONObject.parseObject(JsonContext);
                        } catch (Exception e) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error(" JSON file error" + e.getMessage(), e);
                            return flag;
                        }

                        //获得并处理每条记录
                        String returndata = ob.get("dataType").toString();
                        if (returndata == null || returndata.isEmpty()) {
                            FJRThreadTask.errorFlag = 1;
                            flag = false;
                            logger.error("get dataType failed **************");
                            return flag;
                        } else if (returndata.equals("userInfo")) {
                            //用户接口
                            urls = userUrlStr.split(";");
                            urlsN = userUrlStrNo.split(";");
                            
                            JSONArray dataArray = ob.getJSONArray("record_list");
                            if (dataArray.size() == 0) {
                                FJRThreadTask.errorFlag = 2;
                                flag = false;
                                logger.error(" data file count is 0 **************");
                                return flag;
                            }
                            
                            for (int i = 0; i < dataArray.size(); i++) {
                                String lcPath = BanBkE2p.lcPathBase;
                                JSONObject jsonObject = dataArray.getJSONObject(i);
                                jsonObject.put("sourceSystemCode", src);
                                String dataType = dataType = jsonObject.get("typeName").toString();
                                
                                if (dataType == null || dataType.equals("")) {
                                    logger.info("typeName ------  does not exist");
                                    continue;
                                }
                                Date dt = new Date();
                                SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
                                String dataTime = matter1.format(dt);
                                String fmd5 = jsonObject.get("fileMd5").toString();
                                if (fmd5 == null || fmd5.equals("")) {
                                    logger.info("fileMd5 ------  does not exist");
                                    continue;
                                }
                                logger.info("json fileMd5 ------------: " + fmd5);
                                lcPath = lcPath + dataType + "/" + dataTime + "/" + fmd5 + "/";
                                Map<String, String> lcDfMap = new HashMap<String, String>();
                                boolean attachFlag = true;
                                JSONArray attachArray = null;
                                try {
                                    attachArray = jsonObject.getJSONArray("attachmentList");
                                    if (attachArray.isEmpty() || attachArray.size() == 0 || attachArray == null) {
                                        logger.info("attachmentList no object !!!");
                                        attachFlag = false;
                                    } else {
                                        attachFlag = true;
                                    }
                                } catch (Exception e) {
                                    logger.info("attachmentList no exist!!!" + e.getMessage(), e);
                                    attachFlag = false;
                                }
                                
                                if (attachFlag) {
                                    for (int t = 0; t < attachArray.size(); t++) {
                                        JSONObject attachObject = attachArray.getJSONObject(t);
                                        String arrMd5 = attachObject.get("fileMd5").toString();
                                        if (arrMd5 == null || arrMd5.equals("")) {
                                            logger.info("arrMd5 ------  does not exist");
                                            continue;
                                        }
                                        String ctrlDataPath = fileMap.get(attachObject.get("fileMd5").toString());
                                        String lcHalfPath = attachObject.get("relativePath").toString();
                                        if (lcHalfPath == null || lcHalfPath.equals("") || lcHalfPath.equals(" ")) {
                                            lcHalfPath = attachObject.get("originalFileName").toString();
                                        } else {
                                            lcHalfPath = lcHalfPath.substring(lcHalfPath.indexOf("/") + 1, lcHalfPath.length());
                                        }
                                        String oldDataPath = localFilePath + ctrlDataPath;
                                        String newDataPath = lcPath + lcHalfPath;
                                        JsonUtil.copyFile(oldDataPath, newDataPath);
                                        attachObject.put("attachmentUrl", newDataPath);
                                        lcDfMap.put(attachObject.get("fileMd5").toString(), newDataPath);
                                    }
                                }
                                String lcMainFilePath = lcDfMap.get(fmd5);
                                if (lcMainFilePath == null) {
                                    logger.info("no datafile match lcPath -----------------------!!");
                                    String ctrlDataPath = fileMap.get(fmd5);
                                    String oldDataPath = localFilePath + ctrlDataPath;
                                    String lcN = ctrlDataPath.substring(ctrlDataPath.lastIndexOf("/") + 1, ctrlDataPath.length());
                                    String newDataPath = lcPath + lcN;
                                    JsonUtil.copyFile(oldDataPath, newDataPath);
                                    lcMainFilePath = newDataPath;
                                }
                                logger.info("fileUrl fileShowUrl mmsFileUrl mmsFileShowUrl put json !!");
                                jsonObject.put("fileUrl", lcMainFilePath);
                                jsonObject.put("fileShowUrl", lcMainFilePath);
                                logger.info("fileUrl fileShowUrl mmsFileUrl mmsFileShowUrl put json end !!");
                                
                            }
                        } else if (returndata.equals("sampleInfo")) {
                            //样本接口
                            urls = sampleUrlStr.split(";");
                            urlsN = sampleUrlStrNo.split(";");
                            
                            JSONArray dataArray = ob.getJSONArray("record_list");
                            if (dataArray.size() == 0) {
                                FJRThreadTask.errorFlag = 2;
                                flag = false;
                                logger.error(" data file count is 0 **************");
                                return flag;
                            }
                            
                            for (int i = 0; i < dataArray.size(); i++) {
                                String lcPath = BanBkE2p.lcPathBase;
                                JSONObject jsonObject = dataArray.getJSONObject(i);
                                String dataType = dataType = jsonObject.get("typeName").toString();
                                
                                if (dataType == null || dataType.equals("")) {
                                    logger.info("typeName ------  does not exist");
                                    continue;
                                }
                                Date dt = new Date();
                                SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
                                String dataTime = matter1.format(dt);
                                String fmd5 = jsonObject.get("fileMd5").toString();
                                if (fmd5 == null || fmd5.equals("")) {
                                    logger.info("fileMd5 ------  does not exist");
                                    continue;
                                }
                                String containFile = "true";
                                try {
                                    containFile = jsonObject.get("containFile").toString();
                                } catch (Exception e) {
                                    logger.info("json fileMd5 is " + fmd5 + " doesn't have contailFile!!!" + e.getMessage(), e);
                                }
                                
                                logger.info("json fileMd5 ------------: " + fmd5 + " ,and the containFile is " + containFile);
                                lcPath = lcPath + dataType + "/" + dataTime + "/" + fmd5 + "/";
                                Map<String, String> lcDfMap = new HashMap<String, String>();
                                boolean attachFlag = true;
                                JSONArray attachArray = null;
                                try {
                                    attachArray = jsonObject.getJSONArray("attachmentList");
                                    if (attachArray.isEmpty() || attachArray.size() == 0 || attachArray == null) {
                                        logger.info("attachmentList no object !!!");
                                        attachFlag = false;
                                    } else {
                                        attachFlag = true;
                                    }
                                } catch (Exception e) {
                                    logger.info("attachmentList no exist!!!" + e.getMessage(), e);
                                    attachFlag = false;
                                }
                                
                                if (attachFlag) {
                                    for (int t = 0; t < attachArray.size(); t++) {
                                        JSONObject attachObject = attachArray.getJSONObject(t);
                                        String arrMd5 = attachObject.get("fileMd5").toString();
                                        if (arrMd5 == null || arrMd5.equals("")) {
                                            logger.info("arrMd5 ------  does not exist");
                                            continue;
                                        }
                                        String ctrlDataPath = fileMap.get(attachObject.get("fileMd5").toString());
                                        String lcHalfPath = attachObject.get("relativePath").toString();
                                        if (lcHalfPath == null || lcHalfPath.equals("") || lcHalfPath.equals(" ")) {
                                            lcHalfPath = attachObject.get("originalFileName").toString();
                                        } else {
                                            lcHalfPath = lcHalfPath.substring(lcHalfPath.indexOf("/") + 1, lcHalfPath.length());
                                        }
                                        String oldDataPath = localFilePath + ctrlDataPath;
                                        String newDataPath = lcPath + lcHalfPath;
                                        logger.info(arrMd5 + " begin to copy lc!!!");
                                        JsonUtil.copyFile(oldDataPath, newDataPath);
                                        //双写多媒体库,并添加字段
//                                        String returnKey = uploadFile2Multimedia(oldDataPath);
                                        String returnKey = "";
                                        //mmsAttachmentUrl
                                        attachObject.put("mmsAttachmentUrl", returnKey);
                                        attachObject.put("attachmentUrl", newDataPath);
                                        lcDfMap.put(attachObject.get("fileMd5").toString(), newDataPath);
                                    }
                                }
                                if (containFile != "false") {
                                    String lcMainFilePath = lcDfMap.get(fmd5);
                                    String uploadFile2Multimedia = "";
                                    if (lcMainFilePath == null) {
                                        logger.info("no datafile match lcPath -----------------------!!");
                                        try {
                                            String ctrlDataPath = fileMap.get(fmd5);
                                            String oldDataPath = localFilePath + ctrlDataPath;
                                            String lcN = ctrlDataPath.substring(ctrlDataPath.lastIndexOf("/") + 1, ctrlDataPath.length());
                                            String newDataPath = lcPath + lcN;
                                            JsonUtil.copyFile(oldDataPath, newDataPath);
                                            //双写多媒体库,并添加字段
//                                        uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                            //mmsFileUrl,mmsFileShowUrl
                                            lcMainFilePath = newDataPath;
                                        } catch (Exception e) {
                                            logger.error("local copy error! get filemd5 error." + e.getMessage(), e);
                                        }
                                        logger.info("no datafile match lcPath , and the new lcMainFilePath is " + lcMainFilePath);
                                    }
                                    jsonObject.put("mmsFileUrl", uploadFile2Multimedia);
                                    jsonObject.put("mmsFileShowUrl", uploadFile2Multimedia);
                                    logger.info("mmsFileUrl mmsFileShowUrl put json end !!");
                                    logger.info("fileUrl fileShowUrl put json !!");
                                    jsonObject.put("fileUrl", lcMainFilePath);
                                    jsonObject.put("fileShowUrl", lcMainFilePath);
                                    logger.info("fileUrl fileShowUrl put json end !!");
                                } else {
                                    //没有样本文件，不拷贝龙存，不拼路径
                                    logger.info(fmd5 + " doesn't have datafile ,ane the containFile is " + containFile);
                                }
                            }
                        } else if (returndata.equals("orderInfo")) {
                            urls = orderUrlStr.split(";");
                            urlsN = orderUrlStrNo.split(";");
                            
                            JSONArray dataArray = ob.getJSONArray("record_list");
                            if (dataArray.size() == 0) {
                                FJRThreadTask.errorFlag = 2;
                                flag = false;
                                logger.error(" data file count is 0 **************");
                                return flag;
                            }
                            for (int i = 0; i < dataArray.size(); i++) {
                                String lcPath = BanBkE2p.lcPathBase;
                                JSONObject orderJsonObject = dataArray.getJSONObject(i);
                                JSONObject jsonObject = null;
                                String dataType = "";
                                //指令数据
                                JSONArray orderlist = orderJsonObject.getJSONArray("orderSampleList");
                                for (int m = 0; m < orderlist.size(); m++) {
                                    jsonObject = orderlist.getJSONObject(m);
                                    dataType = jsonObject.get("typeName").toString();
                                    
                                    if (dataType == null || dataType.equals("")) {
                                        logger.info("typeName ------  does not exist");
                                        continue;
                                    }
                                    Date dt = new Date();
                                    SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
                                    String dataTime = matter1.format(dt);
                                    String fmd5 = jsonObject.get("fileMd5").toString();
                                    if (fmd5 == null || fmd5.equals("")) {
                                        logger.info("fileMd5 ------  does not exist");
                                        continue;
                                    }
                                    String containFile = "true";
                                    try {
                                        containFile = jsonObject.get("containFile").toString();
                                    } catch (Exception e) {
                                        logger.info("json fileMd5 is " + fmd5 + " doesn't have contailFile!!!" + e.getMessage(), e);
                                    }
                                    
                                    logger.info("json fileMd5 ------------: " + fmd5 + " ,and the containFile is " + containFile);
                                    lcPath = lcPath + dataType + "/" + dataTime + "/" + fmd5 + "/";
                                    Map<String, String> lcDfMap = new HashMap<String, String>();
                                    boolean attachFlag = true;
                                    JSONArray attachArray = null;
                                    try {
                                        attachArray = jsonObject.getJSONArray("attachmentList");
                                        if (attachArray.isEmpty() || attachArray.size() == 0 || attachArray == null) {
                                            logger.info("attachmentList no object !!!");
                                            attachFlag = false;
                                        } else {
                                            attachFlag = true;
                                        }
                                    } catch (Exception e) {
                                        logger.info("attachmentList no exist!!!" + e.getMessage(), e);
                                        attachFlag = false;
                                    }
                                    
                                    if (attachFlag) {
                                        for (int t = 0; t < attachArray.size(); t++) {
                                            JSONObject attachObject = attachArray.getJSONObject(t);
                                            String arrMd5 = attachObject.get("fileMd5").toString();
                                            if (arrMd5 == null || arrMd5.equals("")) {
                                                logger.info("arrMd5 ------  does not exist");
                                                continue;
                                            }
                                            String ctrlDataPath = fileMap.get(attachObject.get("fileMd5").toString());
                                            String lcHalfPath = attachObject.get("relativePath").toString();
                                            if (lcHalfPath == null || lcHalfPath.equals("") || lcHalfPath.equals(" ")) {
                                                lcHalfPath = attachObject.get("originalFileName").toString();
                                            } else {
                                                lcHalfPath = lcHalfPath.substring(lcHalfPath.indexOf("/") + 1, lcHalfPath.length());
                                            }
                                            String oldDataPath = localFilePath + ctrlDataPath;
                                            String newDataPath = lcPath + lcHalfPath;
                                            logger.info(arrMd5 + " begin to copy lc!!!");
                                            JsonUtil.copyFile(oldDataPath, newDataPath);
                                            //双写多媒体库,并添加字段
                                            String uploadFile2Multimedia = "";
//                                            String uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                            //mmsAttachmentUrl
                                            attachObject.put("mmsAttachmentUrl", uploadFile2Multimedia);
                                            attachObject.put("attachmentUrl", newDataPath);
                                            lcDfMap.put(attachObject.get("fileMd5").toString(), newDataPath);
                                        }
                                    }
                                    
                                    if (containFile != "false") {
                                        String lcMainFilePath = lcDfMap.get(fmd5);
                                        String uploadFile2Multimedia = "";
                                        if (lcMainFilePath == null) {
                                            logger.info("no datafile match lcPath -----------------------!!");
                                            try {
                                                String ctrlDataPath = fileMap.get(fmd5);
                                                String oldDataPath = localFilePath + ctrlDataPath;
                                                String lcN = ctrlDataPath.substring(ctrlDataPath.lastIndexOf("/") + 1, ctrlDataPath.length());
                                                String newDataPath = lcPath + lcN;
                                                JsonUtil.copyFile(oldDataPath, newDataPath);
                                                //双写多媒体库,并添加字段
//                                            uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                                //mmsFileUrl,mmsFileShowUrl
                                                lcMainFilePath = newDataPath;
                                            } catch (Exception e) {
                                                logger.error("local copy error! get filemd5 error." + e.getMessage(), e);
                                            }
                                        }
                                        jsonObject.put("mmsFileUrl", uploadFile2Multimedia);
                                        jsonObject.put("mmsFileShowUrl", uploadFile2Multimedia);
                                        logger.info("mmsFileUrl mmsFileShowUrl put json end !!");
                                        logger.info("fileUrl fileShowUrl put json !!");
                                        jsonObject.put("fileUrl", lcMainFilePath);
                                        jsonObject.put("fileShowUrl", lcMainFilePath);
                                        logger.info("fileUrl fileShowUrl put json end !!");
                                    } else {
                                        //没有样本文件，不拷贝龙存，不拼路径
                                        logger.info(fmd5 + " doesn't have datafile ,ane the containFile is " + containFile);
                                    }
                                }

                                //指令附件
                                JSONArray orderAttachArray = null;
                                boolean orderAttachFlag = true;
                                try {
                                    orderAttachArray = orderJsonObject.getJSONArray("attachmentList");
                                    if (orderAttachArray.isEmpty() || orderAttachArray.size() == 0 || orderAttachArray == null) {
                                        logger.info("orderAttachmentList no object !!!");
                                        orderAttachFlag = false;
                                    } else {
                                        orderAttachFlag = true;
                                    }
                                } catch (Exception e) {
                                    logger.info("orderAttachmentList no exist!!!" + e.getMessage(), e);
                                    orderAttachFlag = false;
                                }
                                
                                if (orderAttachFlag) {
                                    for (int t = 0; t < orderAttachArray.size(); t++) {
                                        JSONObject attachObject = orderAttachArray.getJSONObject(t);
                                        String arrMd5 = attachObject.get("fileMd5").toString();
                                        String arrfilename = attachObject.get("fileName").toString();
                                        String ctrlDataPath = fileMap.get(arrMd5);
                                        if (arrMd5 == null || arrMd5.equals("")) {
                                            logger.info("arrMd5 ------  does not exist");
                                            continue;
                                        }
                                        String oldDataPath = localFilePath + ctrlDataPath;
                                        String newDataPath = "/ybkdata/order/" + currenttime + "/" + arrMd5 + "/" + arrfilename;
                                        logger.info(arrMd5 + " begin to copy lc!!!");
                                        JsonUtil.copyFile(oldDataPath, newDataPath);
                                        //双写多媒体库,并添加字段
                                        String uploadFile2Multimedia = "";
//                                        String uploadFile2Multimedia = uploadFile2Multimedia(oldDataPath);
                                        //mmsAttachmentUrl
                                        attachObject.put("mmsAttachmentUrl", uploadFile2Multimedia);
                                        attachObject.put("attachmentUrl", newDataPath);
                                    }
                                }
                            }
                        }
                        //end handle record   
                    }// end if (flag ) ** if bad data
                    String lastJ = ob.toString();
                    logger.debug("last json !!! ----------- " + lastJ);

                    //修改本地文件
                    File file = new File(jsonFilePath);
                    if (file.exists()) {
                        file.delete();
                    } else {
                        file.createNewFile();
                    }
                    FileWriter fileWriter = new FileWriter(jsonFilePath);
                    fileWriter.write(lastJ);
                    fileWriter.flush();
                    fileWriter.close();
                    long begin = System.currentTimeMillis();
                    while (true) {
                        long end = System.currentTimeMillis();
                        long middle = (end - begin) / 1000;
                        long tmpTimeout = Long.parseLong(sendTimeout);
                        if (middle < tmpTimeout) {
                            logger.info(" runtime: " + middle + "  timeout: " + sendTimeout);
//                            Thread.sleep(3000);
                        } else {
                            logger.error(" http send is killed, because of timeout!");
                            flag = false;
                            break;
                        }
                        int stat = 0;
                        for (int i = 0; i < urls.length; i++) {
//                            stat = JsonUtil.httpPost(urls[i], lastJ, true);
                            stat = JsonUtil.httpPost(urls[i], file);
                            if (stat == 200) {
                                logger.info("json send url " + urls[i] + " send ok !!!");
                                break;
                            } else {
//                                失败的话重试20次啊20次
//                                int count = 0;
//                                while (count < 20) {
//                                    int random = (int) (Math.random() * urls.length);
//                                    logger.info("json send url random:" + random + ",url = " + urls[random] + ",file name = " + file.getName());
//                                    stat = JsonUtil.httpPost(urls[random], file);
//                                    if (stat == 200) {
//                                        logger.info("json send url " + urls[i] + " send ok !!!");
//                                        break;
//                                    }
//                                    count++;
//                                }
                            }
                        }
                        if (stat == 200) {
                            logger.info("json send ok !!!");
                            break;
                        }
                        Thread.sleep(5000);
                    }
                }//end handle json file

            }
            
            logger.info(" JsonUtil end " + df.format(new Date()));
        } catch (Exception ex) {
            FJRThreadTask.errorFlag = 1;
            flag = false;
            logger.error(" parse jsonfile error !!!!!!!! " + ex.getMessage(), ex);
        }
        return flag;
    }

    /**
     * post请求
     *
     * @param url url地址
     * @param lastJ 参数
     * @param noNeedResponse 不需要返回结果
     * @return
     */
    public static int httpPost(String url, String lastJ, boolean noNeedResponse) {
        //post请求返回结果
        DefaultHttpClient httpClient = new DefaultHttpClient();
        JSONObject jsonResult = null;
        HttpPost method = new HttpPost(url);
        int stat = 0;
        try {
            if (null != lastJ) {
                //解决中文乱码问题
                StringEntity entity = new StringEntity(lastJ, "utf-8");
                entity.setContentEncoding("UTF-8");
//                entity.setContentType("application/json");
                entity.setContentType("multipart/form-data");
                method.setEntity(entity);
            }
            HttpResponse result = httpClient.execute(method);
            stat = result.getStatusLine().getStatusCode();
        } catch (IOException e) {
            logger.error("post请求提交失败:" + url, e);
        } finally {
            return stat;
        }
        
    }
    
    public static int httpPost(String url, File file) {
        int sl = 0;
        CloseableHttpClient client = null;
        HttpPost post = null;
        CloseableHttpResponse response = null;
        try {
            client = HttpClients.createDefault();
            
            post = new HttpPost(url);
            FileBody body = new FileBody(file);
            
            HttpEntity entity = MultipartEntityBuilder.create()
                    .addPart("MetaFile", body)
                    .setCharset(Charset.forName("UTF-8"))
                    .build();
            post.setEntity(entity);
            response = client.execute(post);
            String res = HttpResponseParser.getResponseContent(response);
            logger.info("res ---------------- " + res);
            sl = response.getStatusLine().getStatusCode();
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        } finally {
            try {
                if (response != null) {
                    response.close();
                }
            } catch (IOException ex) {
                logger.error(ex.getMessage(), ex);
            }
            try {
                if (client != null) {
                    client.close();
                }
            } catch (IOException ex) {
                logger.error(ex.getMessage(), ex);
            }
            return sl;
        }
        
    }
    
    public String ReadFile(String Path) {
        BufferedReader reader = null;
        String laststr = "";
        StringBuilder stringBuilder = new StringBuilder();
        try {
            FileInputStream fileInputStream = new FileInputStream(Path);
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
            reader = new BufferedReader(inputStreamReader);
            String tempString = null;
            while ((tempString = reader.readLine()) != null) {
//                laststr += tempString;
                stringBuilder.append(tempString);
            }
            reader.close();
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }
//        return laststr;
        return stringBuilder.toString();
    }
    
    public static void delFastF(String fileAbsolutePath, String pangAbsolutePath) {
        
        FileManagerUtil fileManager = new FileManagerUtil();
        
        if (!fileAbsolutePath.equals("null")) {
//                        String fileGroup = fileAbsolutePath.substring(27, 33);
            logger.info("del fastDataFile start --------------------------");
            String[] paths = fileAbsolutePath.split("/");
            String fileGroup = paths[3];
            logger.info("fileGroup = " + fileGroup);
//                        String errorFilePath = fileAbsolutePath.substring(34, fileAbsolutePath.length());
            String errorFilePath = "";
            for (int i = 4; i < paths.length; i++) {
                errorFilePath += paths[i] + "/";
            }
            errorFilePath = errorFilePath.substring(0, errorFilePath.length() - 1);
            logger.info("filePath = " + errorFilePath);
            try {
                fileManager.delFile(fileGroup, errorFilePath);
                logger.info("del fastDataFile success --------------------------");
            } catch (Exception ex) {
                logger.error("delete fast png " + fileAbsolutePath + " error" + ex.getMessage(), ex);
            }
            logger.info("del fastDataFile end --------------------------");
        }
        if (!pangAbsolutePath.equals("null")) {
            logger.info("del fastPngFile start --------------------------");
            String errorPngPath = "";
            String[] paths = pangAbsolutePath.split("/");
            String pngGroup = paths[3];
            logger.info("pngGroup = " + pngGroup);
//                        String errorFilePath = fileAbsolutePath.substring(34, fileAbsolutePath.length());
            for (int i = 4; i < paths.length; i++) {
                errorPngPath += paths[i] + "/";
            }
            errorPngPath = errorPngPath.substring(0, errorPngPath.length() - 1);
            logger.info("errorPngPath = " + errorPngPath);
            try {
                fileManager.delFile(pngGroup, errorPngPath);
                logger.info("success del dataFile -----------------------------");
            } catch (Exception ex) {
                logger.error("delete fast png " + pangAbsolutePath + " error" + ex.getMessage(), ex);
            }
            logger.info("del fastPngFile end --------------------------");
        }
        
    }

    /**
     * 复制单个文件
     *
     * @param oldPath String 原文件路径 如：c:/fqf.txt
     * @param newPath String 复制后路径 如：f:/fqf.txt
     * @return boolean
     */
    public static void copyFile(String oldPath, String newPath) {
        boolean copyFlag = true;
        long time = System.currentTimeMillis();
        File from = new File(oldPath);
        File to = new File(newPath);
        try {
            FileUtils.copyFile(from, to);
            copyFlag = true;
            chmodForFolder(newPath);
            logger.info("copy and chown finish, and use time " + (System.currentTimeMillis() - time) + " ms");
        } catch (Exception e) {
            copyFlag = false;
            logger.warn("复制文件并赋权限操作出错" + e.getMessage(), e);
        }
    }
    
    public static void chmodForFolder(String fileName) throws IOException {
        
        logger.info("chmodForFile:" + fileName);
        String[] filepath = fileName.split(File.separator);
        logger.info(fileName + " .length()= " + fileName.length());
        File wd = new File("/bin");
        Process proc = null;
        try {
            proc = Runtime.getRuntime().exec("/bin/bash", null, wd);
        } catch (IOException e) {
            logger.error("Runtime.getRuntime(): " + e.getMessage(), e);
        }
        if (proc != null) {
            PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);
            out.println("cd /ybkdata/yb/");
            logger.debug("cd /ybkdata/yb/");
            for (int i = 3; i < filepath.length; i++) {
                out.println("chmod 777 " + filepath[i]);
                if (i == filepath.length - 1) {
                    logger.info("file ---------------------" + filepath[i]);
                    break;
                } else {
                    out.println("cd " + filepath[i]);
                    logger.debug("cd " + filepath[i] + "*****************");
                }
                
            }
//            out.println("chmod -R 777 " + filepath[3]);
//            logger.info("chmod -R 777 " + filepath[3]);
            out.println("exit");
            logger.info("chmod exit !!!");
            try {
                
                StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
                // kick off stderr  
                errorGobbler.start();
                StreamGobbler outGobbler = new StreamGobbler(proc.getInputStream(), "STDOUT");
                // kick off stdout  
                outGobbler.start();
                
                logger.debug("wait ...");
                int waitFor = proc.waitFor();
                logger.info("return proc.waitFor(): " + waitFor);
                out.close();
                proc.destroy();
            } catch (Exception e) {
                logger.error("chmod -R 777 error: " + e.getMessage(), e);
            }
        }
        
    }

//    public static void main(String args[]) {
////        JsonUtil jsonUtilNew = new JsonUtil();
////        FastPo fastPo = new FastPo();
////        fastPo.setFilePath("fileurldemo");
////        FastPo fastPo1 = new FastPo();
////        fastPo1.setFilePath("fileurldemo1");
////        FastPo fastPo2 = new FastPo();
////        fastPo2.setFilePath("fileurldemo2");
////        FastPo fastPo3 = new FastPo();
////        fastPo3.setFilePath("fileurldemo3");
////        FastPo fastPo4 = new FastPo();
////        fastPo4.setFilePath("fileurldemo4");
////        HashMap<String, FastPo> m = new HashMap<String, FastPo>();
////        m.put("sadfasdf", fastPo);
////        m.put("123134815696ef1c9bf1f1c9c96ef1c9", fastPo1);
////        m.put("7815696ecbf1c96e6894b779456d330e", fastPo2);
////        m.put("823134815696ecf1c9bf14f1c9c96e5f1c0", fastPo3);
////        m.put("0815696ecbf1c96e6894b779456d3300", fastPo4);
////        List<Map<String, String>> ls = new ArrayList<Map<String, String>>();
////        HashMap<String, String> lm = new HashMap<String, String>();
////        lm.put("name", "/000_20160908_809835ff-faf1-3ba0-a985-085b5f7e8af8.json");
////        ls.add(lm);
//////        JsonUtil.jsonData("/home/wmr/NetBeansProjects/test2/yb_json", m, ls);
//////        /home/wmr/NetBeansProjects/datatest
////        JsonUtil.jsonData("/home/wmr/NetBeansProjects/datatest", m, ls);
////        File from = new File("/home/wmr/1.txt");
////        File to = new File("/home/wmr/NetBeansProjects/2.txt");
////
////        try {
////            FileUtils.copyFile(from, to);
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
//
////        String orclFilePath = "D:/maven/.m2/repository/cn/ac/iie/multimedia/iie.jar";
////        String uploadFile2Multimedia = uploadFile2Multimedia(orclFilePath);
////        System.out.println(uploadFile2Multimedia);
//    }
    public static String uploadFile2Multimedia(String filepath) {
        String mediaPath = "";
        long time = System.currentTimeMillis();
        try {
            mediaPath = mediaclient.uploadFile(filepath);
            logger.info("upload file to multimedia: the filePath is " + filepath + ", and the return key is " + mediaPath + " ,and use time " + (System.currentTimeMillis() - time) + " ms");
        } catch (Exception e) {
            logger.error("the filePath is " + filepath);
            logger.error("upload file to multimedia failed! cause " + e.getMessage(), e);
        }
        return mediaPath;
    }

//    public static String uploadFile2Multimedia(String filepath) {
//        String mediaPath = "";
//        ClientAPI client = new ClientAPI();
////        String uri = "STL://192.168.239.170:26379;192.168.239.171:26379";
//        String uri = BanBkE2p.multimediaurl;
//        try {
////            client.init(uri, "YBK");
//            client.init(uri, BanBkE2p.multimedianamebase);
//            mediaPath = client.uploadFile(filepath);
//            logger.info("uplad file to multimedia: the filePath is " + filepath + ", and the return key is " + mediaPath);
//        } catch (Exception e) {
//            logger.error("the uri is " + uri + " ,and the namebase is " + BanBkE2p.multimedianamebase + " ,and the filePath is " + filepath);
//            logger.error("upload file to multimedia failed! cause " + e.getMessage(), e);
//        } finally {
//            client.quit();
//        }
//        return mediaPath;
//    }
}
